<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title></title>

 <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/css/common.css" />
     <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/js/themes/bootstrap/easyui.css">
  <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/js/themes/icon.css">
   <script type="text/javascript" src="<?php echo site_url(); ?>app/views/js/jquery.min.js"></script>
  <script type="text/javascript" src="<?php echo site_url(); ?>app/views/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<?php echo site_url(); ?>app/views/js/locale/easyui-lang-zh_CN.js"></script>

<script>
  function add(){
    var row = $('#tt').datagrid('getSelected');
     if (row){
      $("#parent").val(row.id);
       $("#father").val(row.name);
         }else{
          $("#parent").val('-1');
          $("#father").val("无上级积分项分类");
         }
         $('#w').dialog('open').dialog('setTitle','新增积分项分类');
    //$('#w').window('open');
  }

function edit(){
   var row = $('#tt').datagrid('getSelected');
     if (row){
          $("#edname").val(row.name);
        //      $("#edmobile").val(row.mobile);
        // $("#edaddress").val(row.address);
        // $("#edcontact").val(row.contact);
          $("#edid").val(row.id);
          // $("#edjarea").combobox('setValue',row.jarea);
          // $("#edjcity").combobox('setValue',row.jcity);
          // $("#edjcounty").combobox('setValue',row.jcounty);
        
         }else{
           alert("you do not selected a rocord!");
         }
    $('#edit').window('open');
 }


  function del(){
 var row = $('#tt').datagrid('getSelected');
if (confirm("确认要删除？")) {
     if (row){
       var id=row.id;
                    $.ajax({
                    type:"post",
                    dataType:"json",
                      url:"del_point_list",
                    data:{id:id},
                    success:function(msg){
                     // alert(msg.status);
                        if(msg.status=="success"){

                           $('#tt').treegrid('reload');

                        }else{
                          alert("不好了什么事情出错了");
                        }
                    }
                  });
         }else{
             alert("你还没有选择一条记录");
         }
       }
  }

function save(){
  var parent=$("#parent").val();
  var name=$("#name").val();
  $.ajax({
  type:"post",
  dataType:"json",
    url:"save_point_list",
  data:{'parent':parent,'name':name},
  success:function(msg){
   // alert(msg.status);
      if(msg.status=="success"){
        $("#parent").val('');
        $("#name").val('');
         $('#tt').treegrid('reload');
         $('#w').window('close');
      }else{
        alert("不好了出错了！");
      }
  }
});

}


function save_edit(){
  var edid=$("#edid").val();
  var edname=$("#edname").val();
  //  var edjarea=$("#edjarea").combobox('getValue');
  // var edjcity=$("#edjcity").combobox('getValue');
  // var edjcounty=$("#edjcounty").combobox('getValue');
  // var edaddress=$("#edaddress").val();
  // var edcontact=$("#edcontact").val();
  // var edmobile=$("#edmobile").val();
  //alert(edjarea+"|"+edjcounty+"|"+edjcity);
  $.ajax({
  type:"post",
  dataType:"json",
    url:"save_edit_point_list",
  data:{'id':edid,'name':edname},
  success:function(msg){
   // alert(msg.status);
      if(msg.status=="success"){

         $('#tt').treegrid('reload');
         $('#edit').window('close');
      }else{
        alert("不好了出错了！");
      }
  }
});

}



function changearea(area,city,county,type){
  var $province = $(area);
  var $city = $(city);
  var $County = $(county);
  var provinceId = $province.combobox({
      onChange:function(newValue, oldValue){

          //刷新数据，重新读取省份下的城市，并清空当前输入的值
          if(newValue != ""){
              var city = $city.combobox({
                  disabled:false,
                  url:'get_area_list/?parent_id='+newValue,
                  valueField:'area_id',
                  textField:'area_name',
                  onLoadSuccess:function(){ //第2选中

                      var combobox = $city.combobox('getData');
                      $city.combobox('setText',combobox[1].area_name).combobox('setValue',combobox[1].area_id);
                  },
                  onChange:function(newValue, oldValue){
                   
                      if(newValue != ""){
                          //刷新数据，重新读取省份下的城市，并清空当前输入的值
                          $County.combobox({
                              disabled:false,
                              url:'get_area_list/?parent_id='+newValue,
                              valueField:'area_id',
                              textField:'area_name',
                              onLoadSuccess:function(){ //第2选中

                                  var combobox = $County.combobox('getData');
                                  $County.combobox('setText',combobox[1].area_name).combobox('setValue',combobox[1].area_id);

                              },
                              onChange:function(newValue,oldValue){
                                
                              }

                          });//.combobox('clear');

                      }
                  }
              });//.combobox('clear');
          }
      }
  });
}

$(function(){
changearea("#jarea","#jcity","#jcounty","j");
changearea("#edjarea","#edjcity","#edjcounty","j");
});


</script>
</head>
<body>
  <h2 class="navfont">积分项分类机构管理:</h2>
   

   <div id="toolbar">
    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add()">新增积分项分类</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit()">编辑积分项分类</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="del()">删除积分项分类</a>
  </div>
  <table title="" id="tt" toolbar="#toolbar" class="easyui-treegrid" style="width:1100px;height:400px"
      data-options="
        url: '<?php  echo site_url();?>index.php/pointlist/get_point_list',
        method: 'get',
        rownumbers: true,
        idField: 'id',
        treeField: 'name'
      ">
    <thead>
      <tr>
        <th data-options="field:'name'" width="220">积分积分项分类名称</th>
<!--         <th data-options="field:'contact'" width="100" align="right">积分项分类负责人</th>
        <th data-options="field:'mobile'" width="150">负责人电话</th>
         <th data-options="field:'jareaname'" width="50">省</th>
          <th data-options="field:'jcityname'" width="50">市</th>
           <th data-options="field:'jcountyname'" width="50">区</th>
         <th data-options="field:'address'" width="400">积分项分类地址</th>
          <th data-options="field:'jarea'" width="10"></th>
          <th data-options="field:'jcity'" width="10"></th>
           <th data-options="field:'jcounty'" width="10"></th> -->
      </tr>
    </thead>
  </table>


  <div id="w" class="easyui-dialog" style="width:800px;height:350px;padding:10px 20px"
      closed="true" buttons="#dlg-buttons">

 <form id="J_Form" class="form-horizontal" action="">

    <div class="row">
      <div class="control-group span8">
            <label class="control-label"><s>*</s>所属积分项分类</label>
            <div class="controls">
            <input type="hidden" name="parent" id="parent" value="">
              <input name="" id="father" type="text" disabled="disabled" value="" data-rules="{required:true}" class="input-normal control-text">
            </div>
          </div>
          <div class="control-group span8">
            <label class="control-label"><s>*</s>积分积分项分类名称</label>
            <div class="controls">
              <input name="name" id="name" type="text" data-rules="{required:true}" class="input-normal control-text">
            </div>
          </div>
  <!--          <div class="control-group span8">
            <label class="control-label"><s>*</s>积分项分类地址</label>
            <div class="controls">
              <input class="easyui-combobox" name="jarea" id="jarea" style="width:100px" value="" data-options="url: '<?php echo site_url();?>index.php/point/get_area_main/?parent_id=0',method: 'get',valueField:'area_id',textField:'area_name',groupField:'group'">
            <input class="easyui-combobox" name="jcity" style="width:100px" id="jcity" value="" data-options="url: '<?php echo site_url();?>index.php/point/get_area_deep/?area_deep=2',method: 'get',valueField:'area_id',textField:'area_name',groupField:'group'">
            <input class="easyui-combobox" name="jcounty" style="width:100px" id="jcounty" value="" data-options="url: '<?php echo site_url();?>index.php/point/get_area_deep/?area_deep=3',method: 'get',valueField:'area_id',textField:'area_name',groupField:'group'">
          
              <input name="address" id="address" type="text" data-rules="{required:true}" class="input-normal control-text">
            </div> -->
          </div>
        </div>
<!-- 
        <div class="row">
          <div class="control-group span8">
            <label class="control-label"><s>*</s>负责人</label>
            <div class="controls">
              <input name="contact" id="contact" type="text" data-rules="{required:true}" class="input-normal control-text">
            </div>
          </div>
          <div class="control-group span8">
            <label class="control-label"><s>*</s>手机号码：</label>
            <div class="controls">
             <input name="mobile" id="mobile" type="text" data-rules="{required:true}" class="input-normal control-text">

            </div>
          </div>
        </div> -->

      </form>

  </div>

 <div id="edit" class="easyui-dialog" style="width:800px;height:350px;padding:10px 20px"
      closed="true" buttons="#dlg-edit-buttons">

 <form id="J_Form" class="form-horizontal" action="">

    <div class="row">

          <div class="control-group span8">
            <label class="control-label"><s>*</s>所属积分项分类</label>
            <div class="controls">
            <input type="hidden" id="edid" value="">
              <input name="name" id="edname" type="text" data-rules="{required:true}" class="input-normal control-text">
            </div>
          </div>
<!--            <div class="control-group span8">
            <label class="control-label"><s>*</s>积分积分项分类地址</label>
            <div class="controls">
             <input class="easyui-combobox" name="edjarea" id="edjarea" style="width:100px" value="" data-options="url: '<?php echo site_url();?>index.php/point/get_area_main/?parent_id=0',method: 'get',valueField:'area_id',textField:'area_name',groupField:'group'">
            <input class="easyui-combobox" name="edjcity" style="width:100px" id="edjcity" value="" data-options="url: '<?php echo site_url();?>index.php/point/get_area_deep/?area_deep=2',method: 'get',valueField:'area_id',textField:'area_name',groupField:'group'">
            <input class="easyui-combobox" name="edjcounty" style="width:100px" id="edjcounty" value="" data-options="url: '<?php echo site_url();?>index.php/point/get_area_deep/?area_deep=3',method: 'get',valueField:'area_id',textField:'area_name',groupField:'group'">
              <input name="edaddress" id="edaddress" type="text" data-rules="{required:true}" class="input-normal control-text">
            </div>
          </div> -->
        </div>

<!--         <div class="row">
          <div class="control-group span8">
            <label class="control-label"><s>*</s>负责人</label>
            <div class="controls">
              <input name="contact" id="edcontact" type="text" data-rules="{required:true}" class="input-normal control-text">
            </div>
          </div>
          <div class="control-group span8">
            <label class="control-label"><s>*</s>手机号码：</label>
            <div class="controls">
             <input name="mobile" id="edmobile" type="text" data-rules="{required:true}" class="input-normal control-text">

            </div>
          </div>
        </div> -->

      </form>

  </div>


<div id="dlg-buttons">
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="save()">保存</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#w').dialog('close')">取消</a>
  </div>
<div id="dlg-edit-buttons">
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="save_edit()">保存</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#edit').dialog('close')">取消</a>
  </div>
</body>
</html>
